<?php
 
// this file must be stored in:
// protected/components/WebUser.php
 
class WebUser extends CWebUser {
 
  // Store model to not repeat query.
  private $_model;
 
  // Return first name.
  // access it by Yii::app()->user->first_name
  function level(){
  
    $user = $this->loadUser(Yii::app()->user->id);
  	
    return $user->level;
  }
  function level2(){
  	
  		$id = Yii::app()->request->getParam(id);
  		if($id!=""){
  			$user=User::model()->findByPk($id);
  			return $user->level;
  		}else{
  			$level = Yii::app()->request->getParam(level);
  			return $level;
  		} 		
  }
  // 增加一个level3 主要是由user_id参数得出用户的level
  function level3(){
  	$user_id = Yii::app()->request->getParam(user_id);
  	if($user_id!=""){
  		$user=User::model()->findByPk($user_id);
  		return $user->level;
  	}else{
  		$level = Yii::app()->request->getParam(level);
  		return $level;
  	}
  }
  //获取用户的父ID
  function userParentId(){
  	$user = $this->loadUser(Yii::app()->user->id);
  	if($user->parentId == 0){
  		return $user->user_id;
  	}else{
  		return $user->parentId;
  	}
  }
  
  // Load user model.
  protected function loadUser($id=null)
    {
        if($this->_model===null)
        {
            if($id!==null)
                $this->_model=User::model()->findByPk($id);
        }
        return $this->_model;
    }
    /**
     * 验证用户是否购买路由服务
     */
    public function checkAccount(){
	    $bool = User::model()->ckAccount();
	    return $bool;
    }
    public function login($identity, $duration=0) {
//        $this->setState('__userInfo', $identity->getUser());
        $this->authTimeout=time()+3600;
        parent::login($identity, $duration);
    }
}
